package de.bmuskalla.brainfuck.ui.editor.editors;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;

public class BFConfiguration extends SourceViewerConfiguration {
	private BFDoubleClickStrategy doubleClickStrategy;
	private BFColorManager colorManager;

	public BFConfiguration(BFColorManager colorManager) {
		this.colorManager = colorManager;
	}

	public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
		return new String[] { IDocument.DEFAULT_CONTENT_TYPE };
	}

	public ITextDoubleClickStrategy getDoubleClickStrategy(
			ISourceViewer sourceViewer, String contentType) {
		if (doubleClickStrategy == null)
			doubleClickStrategy = new BFDoubleClickStrategy();
		return doubleClickStrategy;
	}

	public IPresentationReconciler getPresentationReconciler(
			ISourceViewer sourceViewer) {
		PresentationReconciler reconciler = new PresentationReconciler();

		// DefaultDamagerRepairer dr =
		// new DefaultDamagerRepairer(getXMLTagScanner());
		// reconciler.setDamager(dr, BFPartitionScanner.XML_TAG);
		// reconciler.setRepairer(dr, BFPartitionScanner.XML_TAG);

		// dr = new DefaultDamagerRepairer(getXMLScanner());
		// reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
		// reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
		//
		NonRuleBasedDamagerRepairer ndr = new NonRuleBasedDamagerRepairer(
				new TextAttribute(colorManager
						.getColor(IBFColorConstants.BF_COMMENT)));
		reconciler.setDamager(ndr, BFPartitionScanner.BF_COMMENT);
		reconciler.setRepairer(ndr, BFPartitionScanner.BF_COMMENT);
		return reconciler;
	}

}